﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

public partial class Mod_ReportManage_frm_IdentifyNoQuery : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {        
            this.labMessage.Text = "";                  
    }

    public void ChangPage(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_CorporationSet = new ClsPropertyDAL();
        DataSet dst = cls_CorporationSet.SetOrGetCorporationDataSet;

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            string strKey = ((LinkButton)sender).CommandName;
            int intPageIndex = this.dgrdResult.CurrentPageIndex;
            int intPageCounts = this.dgrdResult.PageCount;

            if (strKey == "0")
            {
                intPageIndex = 0;
            }
            else if (strKey == "1")
            {
                if (intPageIndex > 0) intPageIndex -= 1;
            }
            else if (strKey == "2")
            {
                if (intPageIndex < intPageCounts - 1) intPageIndex += 1;
            }
            else
            {
                intPageIndex = intPageCounts - 1;
            }

            this.BindCorporationSetsByDataView(dst, intPageIndex);
        }
    }
    
    private void GetCorporationSets()
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            ClsCorporationDAL cls_CorporationSet = new ClsCorporationDAL();
            //DataSet dst = cls_CorporationSet.GetCorporations("00", strUserID, "DS000101");
            DataSet dst = null;
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                cls_Property.SetOrGetCorporationDataSet = dst;

                this.BindCorporationSetsByDataView(dst, 0);
            }
            else
            {
                this.lblRsCounts.Text = "共0条记录";
                this.lblPageCounts.Text = "共0页";
                this.lblCurrPage.Text = "当前第0页";
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = false;
                this.lblRsCounts.ForeColor = this.lblPageCounts.ForeColor = this.lblCurrPage.ForeColor = this.lblGoTxt1.ForeColor = this.lblGoTxt2.ForeColor = Color.FromArgb(172, 168, 153);
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>parent.window.location.href='index.aspx'</script>";
        }
    }

    private void BindCorporationSetsByDataView(DataSet dst, int CurrPageIndex)
    {
        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dgrdResult.CurrentPageIndex = CurrPageIndex;
            this.dgrdResult.DataSource = dst;
            this.dgrdResult.DataBind();

            this.lblRsCounts.Text = "共" + dst.Tables[0].Rows.Count + "条记录";
            this.lblPageCounts.Text = "共" + this.dgrdResult.PageCount + "页";
            this.lblCurrPage.Text = "当前第" + (this.dgrdResult.CurrentPageIndex + 1) + "页";
            this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = true;
            this.lblRsCounts.ForeColor = this.lblPageCounts.ForeColor = this.lblCurrPage.ForeColor = this.lblGoTxt1.ForeColor = this.lblGoTxt2.ForeColor = Color.FromArgb(78, 78, 78);

            if (this.dgrdResult.PageCount == 1)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = this.lbtnNext.Enabled = this.lbtnEnd.Enabled = this.txtGo.Enabled = false;
                this.lblGoTxt1.ForeColor = this.lblGoTxt2.ForeColor = Color.FromArgb(172, 168, 153);
            }
            else if (this.dgrdResult.CurrentPageIndex == this.dgrdResult.PageCount - 1)
            {
                this.lbtnNext.Enabled = this.lbtnEnd.Enabled = false;
            }
            else if (this.dgrdResult.CurrentPageIndex == 0)
            {
                this.lbtnFirst.Enabled = this.lbtnPrev.Enabled = false;
            }
        }
        this.dgrdResult.DataBind();
    }

    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        ClsAutoGeneNoDAL cls_AutoGeneNoDAL = new ClsAutoGeneNoDAL();
        string strIdentifyNo = this.txtIdentifyNo.Text.Trim();//识别码
        string strBodNo = this.txtBodNo.Text.Trim();//单据号

        if (strIdentifyNo.Length == 0 && strBodNo.Length == 0)
        {
            //this.labMessage.Text = "<script language='javascript'>alert('请输入查询条件！');</script>";
        }
        else
        {
            DataSet dst = cls_AutoGeneNoDAL.GetQueryGivenIdentifyNo(strIdentifyNo, strBodNo);
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                ClsPropertyDAL cls_Property = new ClsPropertyDAL();
                cls_Property.SetOrGetCorporationDataSet = dst;
                this.BindCorporationSetsByDataView(dst, 0);
            }
            else
            {
                this.labMessage.Text = "<script language='javascript'>alert('搜索结果为空！');</script>";
                //this.BindCorporationSetsByDataView(dst, 0);
            }
        }
                
    }       
}
